package com.pan.kang.util.mock;


import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;


public class UnitTestObjectGeneratorUtil {

    public static void generatorUnitTestObject(String className, String packageName)
            throws Exception {
        MockerTestObject testObject = new MockerTestObject();
        testObject.setClassName(className);
        testObject.setObjectName(StringUtil.strConvertLowerCamel(className));

        List<MockerTestObject.Field> codeFieldList = new ArrayList<>();
        Class<?> clazz = Class.forName(packageName + "." + className);
        Field[] fields = clazz.getDeclaredFields();
        for (Field field : fields) {
            MockerTestObject.Field codeField = new MockerTestObject.Field();
            String fieldName = field.getName();
            codeField.setSetMethod("set" + StringUtil.strConvertUpperCamel(fieldName));
            codeField.setValue(RandomTestDataUtil.getDataValue(field.getType().getName(), fieldName));
            codeFieldList.add(codeField);
        }
        testObject.setFieldList(codeFieldList);
        MockerConfig.generatorUnitTestObject(testObject);

    }
}
